package com.haven123.cloudapp.rabbitmq.Config;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class QueueConfig {
    public static final String queue_n1="queue_1";
    public static final String queue_n2="queue_2";
    public static final String queue_n3="queue_3";
    public static final String queue_n4="queue_4";
    public static final String queue_n5="queue_5";
    @Bean
    public Queue queue1(){
        return QueueBuilder.nonDurable(queue_n1).build();
    }
    @Bean
    public Queue queue2(){
        return QueueBuilder.nonDurable(queue_n2).build();
    }
    @Bean
    public Queue queue3(){
        return QueueBuilder.nonDurable(queue_n3).build();
    }
    @Bean
    public Queue queue4(){
        //如果取消队列4的消费者监听，那么因为超时会被放入设置的死信队列里面。
        Map<String,Object> args=new HashMap<String,Object>();
        args.put("x-message-ttl",10000); //1o秒过期时间，过期之后放入死信队列,死信队列就是其他队列不要的信息放入的队列也是一个普通的队列
        args.put("x-dead-letter-exchange","direct_exhange_dlx");
        args.put("x-dead-letter-routing-key","eight");
        return QueueBuilder.nonDurable(queue_n4).withArguments(args).build();
    }
    @Bean
    public Queue queue5(){
        return QueueBuilder.nonDurable(queue_n5).build();
    }
}
